import 'package:cms/components/term_items.dart';
import 'package:cms/models/term.dart';
import 'package:cms/pages/categories/state/detail/detail_cubit.dart';
import 'package:cms/pages/categories/state/detail/detail_state.dart';
import 'package:cms/views/list_views/single_list_view.dart';
import 'package:common/export/bloc.dart';
import 'package:common/export/tools.dart';
import 'package:common/utils/lara_press_verify.dart';
import 'package:components/lara_press_app_bar.dart';
import 'package:components/lara_press_box.dart';
import 'package:components/lara_press_img.dart';
import 'package:components/lara_press_text.dart';
import 'package:flutter/material.dart';
import 'package:theme/colors.dart';

class LaraPressCmsCategoriesDetailPage extends StatelessWidget {
  final int id;
  const LaraPressCmsCategoriesDetailPage({super.key, required this.id});

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (BuildContext context) => CmsCategoriesDetailCubit(id: id),
      child: Builder(builder: (context) => _buildPage(context)),
    );
  }

  Widget _buildPage(BuildContext context) {
    final cubit = BlocProvider.of<CmsCategoriesDetailCubit>(context);
    return Scaffold(
      appBar: LaraPressAppBar(title: '分类详情', isTransparent: true),
      extendBodyBehindAppBar: true,
      body: CustomScrollView(
        slivers: [
          SliverToBoxAdapter(
            child: BlocBuilder<CmsCategoriesDetailCubit, CmsCategoriesDetailState>(
              builder: (context, state) {
                return Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    LaraPressImg(img: '${state.term?.cover}', height: 0.3.sh),
                    LaraPressBoxConvenience.card(
                      borderRadius: 0,
                      child: Column(
                        spacing: 6.h,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Row(
                            spacing: 10.w,
                            children: [
                              LaraPressText(
                                text: state.term?.name ?? "",
                                type: LaraPressTextType.listTitle,
                                fontWeight: FontWeight.bold,
                              ),
                              Spacer(),
                              OutlinedButton(
                                onPressed: () {},
                                style: OutlinedButton.styleFrom(
                                  side: BorderSide(
                                    color: Theme.of(context).primaryColor,
                                  ),
                                  shape: RoundedRectangleBorder(
                                    borderRadius: BorderRadius.circular(4.r),
                                  ),
                                  padding: EdgeInsets.symmetric(
                                    horizontal: 10.w,
                                  ),
                                  visualDensity: VisualDensity.compact,
                                ),
                                child: LaraPressText(
                                  text: '订阅',
                                  type: LaraPressTextType.listMeta,
                                  color: Theme.of(context).primaryColor,
                                ),
                              ),
                            ],
                          ),
                          LaraPressText(
                            text:
                                '${LaraPressVerify.isEmpty(state.term?.description) ? '该分类暂无描述' : state.term?.description}',
                            type: LaraPressTextType.listContent,
                          ),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Row(
                                spacing: 6.w,
                                children: [
                                  Icon(
                                    OctIcons.book,
                                    size: 14.sp,
                                    color: LaraPressColors.listMeta,
                                  ),
                                  LaraPressText(
                                    text: '文章数：${state.term?.count ?? 0}',
                                    type: LaraPressTextType.listMeta,
                                  ),
                                ],
                              ),
                              Row(
                                spacing: 6.w,
                                children: [
                                  Icon(
                                    OctIcons.people,
                                    size: 14.sp,
                                    color: LaraPressColors.listMeta,
                                  ),
                                  LaraPressText(
                                    text: '作者数：${state.term?.count ?? 0}',
                                    type: LaraPressTextType.listMeta,
                                  ),
                                ],
                              ),
                              Row(
                                spacing: 6.w,
                                children: [
                                  Icon(
                                    OctIcons.bookmark,
                                    size: 14.sp,
                                    color: LaraPressColors.listMeta,
                                  ),
                                  LaraPressText(
                                    text: '订阅数：${state.term?.count ?? 0}',
                                    type: LaraPressTextType.listMeta,
                                  ),
                                ],
                              ),
                            ],
                          ),
                        ],
                      ),
                    ),
                  ],
                );
              },
            ),
          ),
          SliverToBoxAdapter(child: SizedBox(height: 5.h)),
          LaraPressSingleListView(
            categoryId: id,
            isCustomScrollView: false,
            showCategory: false,
          ),
        ],
      ),
    );
  }
}
